Executed: Mon Mar 27 11:48:57 2017
Duration: 5 seconds.
In [1]:
from fretbursts import fretmath
In [2]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from cycler import cycler
import seaborn as sns
%matplotlib inline
%config InlineBackend.figure_format='retina' # for hi-dpi displays
In [3]:
import matplotlib as mpl
from cycler import cycler
bmap = sns.color_palette("Set1", 9)
colors = np.array(bmap)[(1,0,2,3,4,8,6,7), :]
mpl.rcParams['axes.prop_cycle'] = cycler('color', colors)
colors_labels = ['blue', 'red', 'green', 'violet', 'orange', 'gray', 'brown', 'pink', ]
for c, cl in zip(colors, colors_labels):
locals()[cl] = tuple(c) # assign variables with color names
sns.palplot(colors)
In [4]:
sns.set_style('whitegrid')
Load the leakage coefficient from disk (computed in Multi-spot 5-Samples analyis - Leakage coefficient fit):
In [5]:
leakage_coeff_fname = 'results/Multi-spot - leakage coefficient KDE wmean DexDem.csv'
leakageM = float(np.loadtxt(leakage_coeff_fname, ndmin=1))
print('Multispot Leakage Coefficient:', leakageM)
Load the direct excitation coefficient ($d_{dirT}$) from disk (computed in usALEX - Corrections - Direct excitation physical parameter):
In [6]:
dir_ex_coeff_fname = 'results/usALEX - direct excitation coefficient dir_ex_t beta.csv'
dir_ex_t = float(np.loadtxt(dir_ex_coeff_fname, ndmin=1))
print('Direct excitation coefficient (dir_ex_t):', dir_ex_t)
Multispot PR for FRET population:
In [7]:
mspot_filename = 'results/Multi-spot - dsDNA - PR - all_samples all_ch.csv'
E_pr_fret = pd.read_csv(mspot_filename, index_col=0)
E_pr_fret
Out[7]:
Corrected $E$ from μs-ALEX data:
In [8]:
data_file = 'results/usALEX-5samples-E-corrected-all-ph.csv'
data_alex = pd.read_csv(data_file).set_index('sample')#[['E_pr_fret_kde']]
data_alex.round(6)
Out[8]:
In [9]:
E_alex = data_alex.E_gauss_w
E_alex
Out[9]:
In [10]:
import lmfit
In [11]:
def residuals(params, E_raw, E_ref):
gamma = params['gamma'].value
# NOTE: leakageM and dir_ex_t are globals
return E_ref - fretmath.correct_E_gamma_leak_dir(E_raw, leakage=leakageM, gamma=gamma, dir_ex_t=dir_ex_t)
In [12]:
params = lmfit.Parameters()
params.add('gamma', value=0.5)
In [13]:
E_pr_fret_mean = E_pr_fret.mean(1)
E_pr_fret_mean
Out[13]:
In [14]:
m = lmfit.minimize(residuals, params, args=(E_pr_fret_mean, E_alex))
lmfit.report_fit(m.params, show_correl=False)
In [15]:
E_alex['12d'], E_pr_fret_mean['12d']
Out[15]:
In [16]:
m = lmfit.minimize(residuals, params, args=(np.array([E_pr_fret_mean['12d']]), np.array([E_alex['12d']])))
lmfit.report_fit(m.params, show_correl=False)
In [17]:
print('Fitted gamma(multispot):', m.params['gamma'].value)
In [18]:
multispot_gamma = m.params['gamma'].value
multispot_gamma
Out[18]:
In [19]:
E_fret_mch = fretmath.correct_E_gamma_leak_dir(E_pr_fret, leakage=leakageM, dir_ex_t=dir_ex_t,
gamma=multispot_gamma)
E_fret_mch = E_fret_mch.round(6)
E_fret_mch
Out[19]:
In [20]:
E_fret_mch.to_csv('results/Multi-spot - dsDNA - Corrected E - all_samples all_ch.csv')
In [21]:
'%.5f' % multispot_gamma
Out[21]:
In [22]:
with open('results/Multi-spot - gamma factor.csv', 'wt') as f:
f.write('%.5f' % multispot_gamma)
In [23]:
norm = (E_fret_mch.T - E_fret_mch.mean(1))#/E_pr_fret.mean(1)
norm_rel = (E_fret_mch.T - E_fret_mch.mean(1))/E_fret_mch.mean(1)
norm.plot()
norm_rel.plot()
Out[23]:
In [24]:
sns.set_style('whitegrid')
In [25]:
CH = np.arange(8)
CH_labels = ['CH%d' % i for i in CH]
dist_s_bp = [7, 12, 17, 22, 27]
In [26]:
fontsize = 16
fig, ax = plt.subplots(figsize=(8, 5))
ax.plot(dist_s_bp, E_fret_mch, '+', lw=2, mew=1.2, ms=10, zorder=4)
ax.plot(dist_s_bp, E_alex, '-', lw=3, mew=0, alpha=0.5, color='k', zorder=3)
plt.title('Multi-spot smFRET dsDNA, Gamma = %.2f' % multispot_gamma)
plt.xlabel('Distance in base-pairs', fontsize=fontsize);
plt.ylabel('E', fontsize=fontsize)
plt.ylim(0, 1); plt.xlim(0, 30)
plt.grid(True)
plt.legend(['CH1','CH2','CH3','CH4','CH5','CH6','CH7','CH8', u'μsALEX'],
fancybox=True, prop={'size':fontsize-1},
loc='best');
NOTE The fact the we fit the 27d with a single Gaussian may account for the slight shift of the FRET efficiency compared to the us-ALEX measurements. The shift is bigger when using an asymmetric-gaussian model for multi-spot fitting. Probably, for consistency with us-ALEX fitting we should stick to the plain gaussian.